package com.leectrl.utils;

import android.os.Build;

import androidx.annotation.RequiresApi;

import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import org.springframework.lang.NonNull;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

public class Action<T> {
    @NonNull
    private Object object;
    @NonNull
    private Method method;

    private boolean injectionFullhttprequest;
    private boolean checkSession;

    public Action(@NonNull Object object, @NonNull Method method) {
        this.object = object;
        this.method = method;
    }

    @NonNull
    public Object getObject() {
        return object;
    }

    public void setObject(@NonNull Object object) {
        this.object = object;
    }

    @NonNull
    public Method getMethod() {
        return method;
    }

    public void setMethod(@NonNull Method method) {
        this.method = method;
    }

    public boolean isCheckSession() {
        return checkSession;
    }

    public void setCheckSession(boolean checkSession) {
        this.checkSession = checkSession;
    }

    public boolean isInjectionFullhttprequest() {
        return injectionFullhttprequest;
    }

    public void setInjectionFullhttprequest(boolean injectionFullhttprequest) {
        this.injectionFullhttprequest = injectionFullhttprequest;
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public T call(Object... args) {
        try {
            return (T) method.invoke(object, args);
        } catch (IllegalAccessException | InvocationTargetException e) {
           e.printStackTrace();
        }
        return null;
    }

}
